package com.chumi.bootstrap.controller.demo;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chumi.bootstrap.model.standard.demo.TtApplicationUser;
import com.chumi.bootstrap.service.demo.TtApplicationUserService;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.llsfw.core.controller.base.BaseController;
import com.llsfw.core.datasource.DBContextHolder;
import com.llsfw.core.exception.SystemException;
import com.llsfw.core.pagequery.PageResult;
import com.llsfw.generator.model.standard.system.TtDynamicDataSource;




@Controller
@RequestMapping("TtApplicationUserController")
public class TtApplicationUserController extends BaseController{

    @Autowired
    private TtApplicationUserService taus;   
    
	@RequestMapping("getUserList")
	@ResponseBody
    public List<TtApplicationUser> getUserList(HttpServletRequest request) throws IOException{
		return taus.getUserList();	 
    }
	
	@RequestMapping("checkUser")
	@ResponseBody
    public Boolean checkUser(HttpServletRequest request, String value) throws IOException{
		return taus.checkUser(value);
    }	
	
    @RequestMapping("getUserListByPageQuery")
    @ResponseBody
    public PageResult getUserListByPageQuery(HttpServletRequest request, int page, int pagesize, String condition) throws SystemException, JsonParseException, JsonMappingException, IOException {
    	ObjectMapper mapper = new ObjectMapper();
    	TtApplicationUser user = new TtApplicationUser();
    	if(condition!=null&&!condition.equals("")){
    		user = mapper.readValue(condition,TtApplicationUser.class);
    	}    	
    	PageResult pr = taus.getUserListByPageQuery(pagesize,page,user);
    	return pr;
    }
	
}
